<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.deproduct}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
        <h:form >
           <script type="text/javascript">  
                    
                function handleSaveDeprod(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgDeproduct.hide();  
                    }  
                }
                
                function handleDeleteDeprod(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgDeldeproduk.hide();  
                    }  
                }
                
            </script>

            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton value="#{bundle.btnNew}"
                                     icon="ui-icon-document"
                                     action="#{deproductBean.newData()}"  
                                     oncomplete="dlgDeproduct.show()"
                                     update=":#{utilityBean.findClientId('displayDeproduct')}" process="@this"> 
                        <pe:resetEditableValues for="displayDeproduct"/>
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgDeproduct.show()"
                                     actionListener="#{deproductBean.openData()}"
                                     icon="ui-icon-disk" 
                                     update=":#{utilityBean.findClientId('displayDeproduct')}" > 
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnDelete}" icon="ui-icon-trash"
                                     onclick="dlgDeldeproduk.show()" /> 

                    <p:commandButton type="push" value="#{bundle.btnPrint}" icon="ui-icon-print"/>
                </p:toolbarGroup>
            </p:toolbar>
            <br />
            <p:dataTable var="deproduct" value="#{deproductBean.deproducts}" id="dtDeproducts" resizableColumns="true"
                         selection="#{deproductBean.selectedData}" selectionMode="single" rowKey="#{deproduct.deproductId}" 
                         rowIndexVar="noUrut" paginator="true" rows="10" paginatorPosition="bottom"  
                         paginatorTemplate="{CurrentPageReport} {PreviousPageLink} {NextPageLink} ">
                
                <p:column style="width:12px;" >
                    <f:facet name="header">No</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                </p:column>
                
                <p:column style="width:auto;" sortBy="#{deproduct.productName}">
                    <f:facet name="header">#{bundle.globalName}</f:facet>
                    <h:outputText value="#{deproduct.productName}" />
                </p:column>
                
                <p:column style="width:30px;">
                    <f:facet name="header">#{bundle.period}</f:facet>
                    <h:outputText value="#{constantaBean.getDeptPeriodText(deproduct.periodOpt)}" />
                </p:column>
                
                <p:column style="width:20px;">
                    <f:facet name="header">#{bundle.numOfPeriod}</f:facet>
                    <h:outputText value="#{deproduct.numOfPeriod}" styleClass="numPos" >
                        <f:convertNumber groupingUsed="true" />
                    </h:outputText>
                </p:column>
                
                <p:column style="width:150px;">
                    <f:facet name="header">#{bundle.depGlaccnt}</f:facet>
                    <h:outputText value="#{deproductBean.getLisLabeltName(deproductBean.avblGL, deproduct.depGlaccountId)}" />
                </p:column>
                <p:column style="width:150px;">
                    <f:facet name="header">#{bundle.interestGlccnt}</f:facet>
                    <h:outputText value="#{deproductBean.getLisLabeltName(deproductBean.avblGL, deproduct.interestGlaccountId)}" />
                </p:column>
                <p:column style="width:150px;">
                    <f:facet name="header">#{bundle.penaltyGlaccnt}</f:facet>
                    <h:outputText value="#{deproductBean.getLisLabeltName(deproductBean.avblGL, deproduct.penaltyGlaccountId)}" />
                </p:column>
                <p:column style="width:150px;">
                    <f:facet name="header">#{bundle.tax}</f:facet>
                    <h:outputText value="#{deproductBean.getLisLabeltName(deproductBean.avblTax, deproduct.taxId)}" />
                </p:column>
            </p:dataTable>
          
            <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                             header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgDeldeproduk">
                <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnYes}" update="dtDeproducts" process="@this"
                                         oncomplete="handleDeleteDeprod(xhr, status, args)"  
                                         actionListener="#{deproductBean.delete()}" />  
                        <p:commandButton value="#{bundle.btnCancel}" onclick="dlgDeldeproduk.hide()" type="button" />  
                    </f:facet>
                </h:panelGrid>  
            </p:confirmDialog> 
        </h:form>
            
            <p:dialog header="#{bundle.deproduct}" widgetVar="dlgDeproduct" closable="true" dynamic="true" modal="true" appendToBody="true">
                <p:ajax event="close" listener="#{deproductBean.handleClose}"/>
                <h:form>
                                
                <h:panelGrid id="displayDeproduct" columns="2" styleClass="addELIT">
                     <p:tabView activeIndex="0" rendered="#{deproductBean.unsaveData!=null}">
                         <p:tab title="#{bundle.tabproduct}" >
                             <h:panelGrid columns="3" cellpadding="0" cellspacing="5">
                                <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{deproductBean.unsaveData!=null}" >
                                    <p:inputText value="#{deproductBean.unsaveData.productName}" style="width: 170px" 
                                                required="true" label="#{bundle.globalName}" id="deproductName1"
                                                requiredMessage="#{bundle.globalName} #{bundle.requiredInput}" >
                                        <p:ajax update="msgdeproductName1" process="@this"/>
                                    </p:inputText>
                                    <p:message id="msgdeproductName1" for="deproductName1" display="icon" />
                                </h:panelGrid>

                                <h:outputLabel value= "#{bundle.period}" /><h:outputLabel value= ":" />
                                <p:selectOneMenu value="#{deproductBean.unsaveData.periodOpt}" required="true" style="width: 170px" 
                                                rendered="#{deproductBean.unsaveData!=null}">
                                    <f:selectItems value="#{deproductBean.avblPeriod}"/>
                                </p:selectOneMenu>

                                <h:outputLabel value= "#{bundle.numOfPeriod}" /><h:outputLabel value= ":" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{deproductBean.unsaveData!=null}">
                                    <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="9999" minValue="0" symbol=" #{bundle.day}" symbolPosition="s"
                                            styleClass="integer" value="#{deproductBean.unsaveData.numOfPeriod}" style="width: 70px" 
                                            label="#{bundle.numOfPeriod}" id="deprodukNumOfPeriod1" required="true"
                                            requiredMessage="#{bundle.numOfPeriod} #{bundle.requiredInput}">
                                            <p:ajax update="msgdeprodukNumOfPeriod1" />
                                    </pe:inputNumber>
                                    <p:message id="msgdeprodukNumOfPeriod1" for="deprodukNumOfPeriod1" display="icon" />
                                </h:panelGrid>

                                <h:outputLabel value= "#{bundle.tax}" /><h:outputLabel value= ":" />
                                <p:selectOneMenu value="#{deproductBean.unsaveData.taxId}" required="true" 
                                                rendered="#{deproductBean.unsaveData!=null}" style="width: 170px" >
                                        <f:selectItems value="#{deproductBean.avblTax}"  />
                                </p:selectOneMenu> 
                             </h:panelGrid>
                         </p:tab>
                         
                         <p:tab title="#{bundle.intRate}" >
                             <h:panelGrid columns="3" cellpadding="0" cellspacing="5">
                                <p:outputLabel value= "#{bundle.depGlaccnt}" for="deproddepGlaccnt" /><h:outputLabel value= ":" />
                                <p:selectOneMenu  value="#{deproductBean.depGlaccount}" rendered="#{deproductBean.unsaveData!=null}" 
                                                  style="width: 300px;" var="glacc1" converter="glaccnt" id="deproddepGlaccnt" required="true">
                                    <f:selectItem rendered="#{deproductBean.depGlaccount!=null}" itemLabel="#{deproductBean.depGlaccount.accountName}" itemValue="#{deproductBean.depGlaccount}" />
                                    <f:selectItems value="#{deproductBean.avblAkun}" var="gl" itemLabel="#{gl.accountName}" itemValue="#{gl}" />
                                    <p:column>#{glacc1.accountNo}</p:column>
                                    <p:column>#{glacc1.accountName}</p:column>
                                </p:selectOneMenu>

                                <p:outputLabel value= "#{bundle.interestGlccnt}" for="deprodinterestGlccnt"/><h:outputLabel value= ":" />
                                <p:selectOneMenu  value="#{deproductBean.interestGlaccount}" rendered="#{deproductBean.unsaveData!=null}" 
                                                  style="width: 300px;" var="glacc1" converter="glaccnt" id="deprodinterestGlccnt" required="true">
                                    <f:selectItem rendered="#{deproductBean.interestGlaccount!=null}" itemLabel="#{deproductBean.interestGlaccount.accountName}" itemValue="#{deproductBean.interestGlaccount}" />
                                    <f:selectItems value="#{deproductBean.avblAkun}" var="gl" itemLabel="#{gl.accountName}" itemValue="#{gl}" />
                                    <p:column>#{glacc1.accountNo}</p:column>
                                    <p:column>#{glacc1.accountName}</p:column>
                                </p:selectOneMenu>
            
                                <p:outputLabel value= "#{bundle.penaltyGlaccnt}" for="deprodpenaltyGlaccount"/><h:outputLabel value= ":" />
                                <p:selectOneMenu  value="#{deproductBean.penaltyGlaccount}" rendered="#{deproductBean.unsaveData!=null}" 
                                                  style="width: 300px;" var="glacc1" converter="glaccnt" id="deprodpenaltyGlaccount" required="true">
                                    <f:selectItem rendered="#{deproductBean.penaltyGlaccount!=null}" itemLabel="#{deproductBean.penaltyGlaccount.accountName}" itemValue="#{deproductBean.penaltyGlaccount}" />
                                    <f:selectItems value="#{deproductBean.avblAkun}" var="gl" itemLabel="#{gl.accountName}" itemValue="#{gl}" />
                                    <p:column>#{glacc1.accountNo}</p:column>
                                    <p:column>#{glacc1.accountName}</p:column>
                                </p:selectOneMenu>
                    
                            </h:panelGrid>
                         </p:tab>
                     </p:tabView>
                </h:panelGrid>
                    
                <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{deproductBean.save()}"
                                         update=":#{utilityBean.findClientId('dtDeproducts')}" id="submitDeprod"
                                         oncomplete="handleSaveDeprod(xhr, status, args)"/>
                        <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgDeproduct.hide()" icon="ui-icon-document" immediate="true"/>
                    </f:facet>
                </h:panelGrid>
                    </h:form>
                <!--<p:defaultCommand target="submitDeprod" /> -->
            </p:dialog> 
        
        </ui:composition>    
    </h:body>
</html>
